/**
 * 
 */
package bingo.validation;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * 验证失败的结果集合类
 */
public class ValidationResults {
	
	private ArrayList<ValidationResult> results = new ArrayList<ValidationResult>();

	private boolean isPass = true;
	
	public void add(ValidationResult result){
		if(!result.isPass()){
			this.isPass = false;
			results.add(result);
		}else{
			//REVIEW: ignore success result
		}
	}
	
	public boolean isPass(){
		return this.isPass;
	}
	
	public Iterator<ValidationResult> iterator(){
		return results.iterator();
	}
	
	public Collection<ValidationResult> getResults(){
		return results;
	}
	
	public String getMessage(){
	    StringBuffer buf = new StringBuffer();
	    for(ValidationResult r : getResults()){
	        buf.append(r.getMessage()).append(",");
	    }
	    String result = buf.toString();
	    return result.length() > 0 ?  result.substring(0,result.length()-1) : result;
	}
	
	public boolean isEmpty(){
		return results.isEmpty();
	}
	
	public ValidationResult getFirst(){
		if(!isEmpty()){
			return results.get(0);
		}else{
			return null;
		}
	}
}
